package com.gec.content.controller;

import com.gec.content.service.ContentCategoryService;
import com.gec.content.service.ContentService;
import com.gec.mall.pojo.*;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: li
 * @Date: 2023/2/6
 * @PACKAGE_NAME:com.gec.content.controller
 * @Project_Name:mall-parent
 * @VERSION: 1.0.0
 */
@RestController
@RequestMapping("/content")
public class ContentController {

    @Autowired
    private ContentService contentService;

    @Autowired
    private ContentCategoryService contentCategoryService;

    @GetMapping("/GetContentCategoryList")
    public RespBean getContentCategory(){
        return RespBean.ok("",contentCategoryService.getContentCategoryList());
    }

    @GetMapping("/getContentByCategoryId")
    public List<TbContent> getContentByCategoryId(Long categoryId){
        return contentService.getContentByCategoryId(categoryId);
    }
    @GetMapping("/GetAllContent")
    public PageResp getAllContent(PageReq pageReq){
        PageHelper.startPage(pageReq.getPage(), pageReq.getSize());
        Page<TbContent> page = (Page<TbContent>)contentService.getAllContent();
        PageResp pageResp = new PageResp();
        pageResp.setTotal(page.getTotal());
        pageResp.setList(page.getResult());
        return pageResp;
    }

    @PostMapping("addContent")
    public RespBean addContent(@RequestBody TbContent tbContent){
        contentService.addContent(tbContent);
        return RespBean.ok("");
    }

    @DeleteMapping("/delContentById/{id}")
    public RespBean delContentById(@PathVariable Long id){
        contentService.delContentById(id);
        return RespBean.ok("");
    }
}
